﻿namespace MDK.Device
{
    public static class ErrorCodeHelper
    {
        public const int DeviceErrorCodeBase = 10000;
        public const int DeviceTimeout = 10001;

        public const int PlcErrorCodeBase = -10000;

        public const int TcpErrorCodeBase = 20000;
        public const int TcpConnectTimeout = TcpErrorCodeBase + 1;
        public const int TcpComError = TcpErrorCodeBase + 2;
        public const int TcpFrameError = TcpErrorCodeBase + 3;

        public const int SerialPortErrorCodeBase = 30000;
        public const int SerialPortNotExist = SerialPortErrorCodeBase + 1;
        public const int SerialPortOccupied = SerialPortErrorCodeBase + 2;
        public const int SerialPortComError = SerialPortErrorCodeBase + 3;

        public const int CameraErrorBase = 40000;
        public const int CameraNotExist = CameraErrorBase + 1; 
        public const int CameraComError = CameraErrorBase + 2;

        public static string GetErrorCodeText(int errorcode)
        {
            switch (errorcode)
            {
                case 0: return "执行成功";

                case DeviceTimeout: return "设备响应超时";

                case PlcErrorCodeBase - 1: return "IP地址或端口参数错误";
                case PlcErrorCodeBase - 2: return "网络连接错错误";
                case PlcErrorCodeBase - 3: return "连接参数错误导致连接失败(如Rack>7、Slot>15等)";
                case PlcErrorCodeBase - 4: return "PLC握手连接异常";
                case PlcErrorCodeBase - 5: return "PLC握手无响应";
                case PlcErrorCodeBase - 6: return "PLC握手响应错误";
                case PlcErrorCodeBase - 10: return "读数据超过最大数据量限制";
                case PlcErrorCodeBase - 11: return "读数据时数据发送异常";
                case PlcErrorCodeBase - 12: return "读数据时PLC响应超时";
                case PlcErrorCodeBase - 13: return "读数据PLC返回格式错误";
                case PlcErrorCodeBase - 14: return "读数据PLC返回数据错误";
                case PlcErrorCodeBase - 15: return "读数据PLC返回数据校验";
                case PlcErrorCodeBase - 18: return "PLC的网络句柄解析错误";
                case PlcErrorCodeBase - 19: return "PLC的网络句柄数据错误";
                case PlcErrorCodeBase - 20: return "写数据超过最大数据量限制";
                case PlcErrorCodeBase - 21: return "写数据时数据发送异常";
                case PlcErrorCodeBase - 22: return "写数据PLC响应超时";
                case PlcErrorCodeBase - 23: return "写数据PLC返回格式错误";
                case PlcErrorCodeBase - 24: return "写数据PLC返回数据错误";
                case PlcErrorCodeBase - 25: return "写数据PLC返回数据校验";
                case PlcErrorCodeBase - 28: return "PLC的网络句柄解析错误";
                case PlcErrorCodeBase - 29: return "PLC的网络句柄数据错误";
                case PlcErrorCodeBase - 31: return "数据转换时源数据处理错误";
                case PlcErrorCodeBase - 32: return "数据转换时目标数据处理错误";
                case PlcErrorCodeBase - 41: return "位操作函数的参数错误";
                case PlcErrorCodeBase - 70: return "PLC内存区域的功能受限制";
                case PlcErrorCodeBase - 80: return "PC系统中无网卡";
                case PlcErrorCodeBase - 81: return "PC的IP地址格式错误";
                case PlcErrorCodeBase - 82: return "PLC的IP地址格式错误";
                case PlcErrorCodeBase - 83: return "PING命令返回错误";
                case PlcErrorCodeBase - 99: return "连接序列号错误或测试次数超过使用限制";

                case SerialPortNotExist: return "串口不存在";
                case SerialPortOccupied: return "串口被占用";
                case SerialPortComError: return "串口通信错误";

                case TcpConnectTimeout: return "TCP连接超时";
                case TcpComError: return "TCP通信错误";
                case TcpFrameError: return "帧错误";

                default: return "未知错误";
            }
        }
    }
}